angular.module('Controller')
.controller('WFAuthorityManageNewCtrl', ($scope,NgTableParams,wfAlert,commonUtil,commonConstant,$http, $uibModalInstance, items) ->
    type=items.type
    $scope.data=items.data
    $scope.modalTitle=if type=='new' then '新建权限' else '编辑权限'
    $scope.typeList=commonConstant.authorizationTypeList()
    $scope.enabledList=commonConstant.enabledList()
    $scope.resourceTypeList=commonConstant.resourceTypeList()
    $scope.newData=()->
        postData={
            authority:$scope.data.authority
            description:$scope.data.description
            enabled:$scope.data.enabled
            type:$scope.data.type
        }
        getParams=commonUtil.transferGetParam(postData)
        $http.post('@ostengar/authority',postData)
        .success((resp)->
            if(resp.code==0)
                console.log('新增权限:',resp)
                $uibModalInstance.close('done')
                wfAlert.toastInfo('新增权限成功')
            else
                wfAlert.toastError('新增权限失败：',resp.message)
        )

    $scope.editData=()->
        putData={
            authority:$scope.data.authority
            description:$scope.data.description
            enabled:$scope.data.enabled
            type:$scope.data.type
        }
        getParams=commonUtil.transferGetParam(putData)
        $http.put('@ostengar/authority/'+$scope.data.id,putData)
        .success((resp)->
            if(resp.code==0)
                console.log('修改权限:',resp)
                wfAlert.toastInfo('修改权限成功')
            else
                wfAlert.toastError('修改权限失败：',resp.message)
        )
    $scope.confirm = ()->
        if type=='new'
            $scope.newData()
        else
            $scope.editData()
    $scope.cancel =()->
        $uibModalInstance.dismiss('cancel')

)